package com.demo.my.Util;


import com.alibaba.druid.pool.DruidDataSource;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

public class DBUtil {
    private static DataSource dataSource;
    static {
        Properties p = new Properties();
        try {
            p.load(DBUtil.class.getResourceAsStream("/jdbc.properties"));
            DruidDataSource source = new DruidDataSource();
            source.configFromPropety(p);
            dataSource=source;
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static Connection getConnection() throws SQLException {
        return dataSource.getConnection();
    }
    public static void close(ResultSet rs, Statement st, Connection conn) throws SQLException {
        if (rs!=null)rs.close();
        if (st!=null)st.close();
        if (conn!=null)conn.close();
    }
}
